package com.bw.packcar.net

import androidx.lifecycle.MutableLiveData
import com.bw.common.entity.DictionariesEntity
import com.bw.common.vm.BaseViewModel
import com.bw.http.utils.zgr.OkHttpClientManager
import com.bw.packcar.model.PackEntity

class CarPackViewModel:BaseViewModel() {

    val packSuccess by lazy { MutableLiveData<List<PackEntity>>() }
    val addPackSuccess by lazy { MutableLiveData<PackEntity>() }
    val deletePackSuccess by lazy { MutableLiveData<String>() }
    val spaceTypeSuccess by lazy { MutableLiveData<List<DictionariesEntity>>() }
    val areaNameSuccess by lazy { MutableLiveData<List<DictionariesEntity>>() }
    val serialNumberSuccess by lazy { MutableLiveData<String>() }

    private val apiService: ApiService = OkHttpClientManager.retrofitInstance.create(ApiService::class.java)

    fun getCarPackByArea(areaId:Int) {

        executeNetwork(
            { apiService.getCarPackByArea(areaId) },
            packSuccess::postValue
        )
    }



    fun addCarPack(packEntity: PackEntity) {

        executeNetwork(
            { apiService.addCarPack(packEntity) },
            addPackSuccess::postValue
        )
    }

    fun deletePackById(id:Int) {

        executeNetwork(
            { apiService.deletePackById(id) },
            deletePackSuccess::postValue
        )
    }

    fun getSpaceType(){
        executeNetwork(
            { apiService.getDictionaries("spaceType") },
            spaceTypeSuccess::postValue
        )
    }

    fun getAreaName(){
        executeNetwork(
            { apiService.getDictionaries("areaName") },
            areaNameSuccess::postValue
        )
    }

    fun getSerialNumber(prefix:String = "zw"){
        executeNetwork(
            { apiService.getSerialNumber(prefix) },
            serialNumberSuccess::postValue
        )
    }

}